#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
ll n,r[N],cnt[N],maxn=0,sum;
int main(){
    freopen("duel.in","r",stdin);
    freopen("duel.out","w",stdout);
    cin>>n;
    for(ll i=1;i<=n;i++){
        cin>>r[i];
        cnt[r[i]]++;
        maxn=max(maxn,r[i]);
    }
    for(ll i=1;i<=n;i++){
        if(cnt[r[i]]==n){
            cout<<n;
            return 0;
        }
        else if(cnt[r[i]]+cnt[maxn]==n&&r[i]<maxn){
            sum=n;
            sum-=cnt[maxn];
            cout<<sum;
            return 0;
        }
    }
    sum=n;
    for(ll i=1;i<=n;i++){
        if(r[i]!=0&&r[i]<r[i+1]&&r[i+1]!=maxn){
            r[i]=0;
            sum--;
        }
        else if(r[i]!=0&&r[i]>r[i+1]&&r[i]!=maxn){
            r[i+1]=0;
            sum--;
        }
    }
    sum-=cnt[maxn];
    cout<<sum;
    return 0;
}
